<?php
class CronCalcDefisTask extends sfBaseTask
{
    protected function configure()
    {
        $this->namespace           = 'cron';
        $this->name                = 'majChallenges';
        $this->briefDescription    = 'MAJ du classement de tout les defis';
        $this->detailedDescription = 'Maj des defis';
        $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
    }

    protected function execute($arguments=array(), $options=array())
    {
    	// Activation de l'usage de la base de donnees.
        $databaseManager = new sfDatabaseManager($this->configuration);

        // Recuperation de la connexion a la base de donnees.
        $pdo = Doctrine_Manager::connection()->getDBh();
 
       	// On récupère la liste des defis actifs
       	$aDefis = DefisTable::getOnlineDefi();
       	
       	if (!$aDefis[0])
       		exit('No challenge');
       	
       	foreach ($aDefis as $oDefi)
       	{
       		ClassementTable::generateClassement($oDefi['id']);
       	}
    }
}
?>